package nl.ViewerServer.ServerManager.DataManager.Objects;

import java.util.ArrayList;
import java.util.HashMap;

public class Modality {
   protected final int                             modalityId;
   protected final transient int                   datasetId;
   protected final String                          name;
   protected final String                          description;
   protected transient Source                      source;
   protected final HashMap<Integer, Visualization> visualizations          = new HashMap<Integer, Visualization>();
   protected final transient ArrayList<Modality>   alignmentsTo            = new ArrayList<Modality>();
   protected String                                serializingAlignmentsTo = "";
   protected final transient String                modalityACL;

   public Modality( int modalityId, String name, String description, int datasetId, int sourceId, String modalityACL ) {
      super();
      this.modalityId = modalityId;
      this.name = name;
      this.description = description;
      this.datasetId = datasetId;
      this.source = new Source( sourceId );
      this.modalityACL = modalityACL;
   }

   public int getDatasetId() {
      return datasetId;
   }

   public String getName() {
      return name;
   }

   public void addAlignment( Modality m2 ) {
      alignmentsTo.add( m2 );
      // update the string that textually describes the alignments (this string is serialized to the client)
      if( serializingAlignmentsTo.length() > 0 ) {
         serializingAlignmentsTo += ", ";
      }
      serializingAlignmentsTo += m2.name;
   }

   public Visualization getVisualization( int visualizationId ) {
      return visualizations.get( visualizationId );
   }

   public void addVisualization( Visualization v ) {
      visualizations.put( v.visualizationId, v );
   }

   public int getModalityId() {
      return modalityId;
   }

   public Source getSource() {
      return source;
   }

   public String toString() {
      return "Modality: [" + modalityId + "/" + name + "/" + description + "/visualizations: " + visualizations.size() + "]";
   }

   public ArrayList<Modality> getAlignmentsTo() {
      return alignmentsTo;
   }

   public String getModalityACL() {
      return modalityACL;
   }
   
   public Modality clone() {
      Modality clone = new Modality(this.modalityId, this.name, this.description, this.datasetId, this.source.sourceId, this.modalityACL);
      
      for(Modality m : alignmentsTo) {
         clone.addAlignment( m );
      }
      
      return clone;
      
   }

   public HashMap<Integer, Visualization> getVisualizations() {
      return visualizations;
   }

}
